<?php defined('RUN_KATANA') or die('Restricted access'); ?>
<?php echo $commander->getListCommandsPanel('n-sa-a-d', ''); ?>
<div class="menu_list">
	<table style="clear:both;" id="menulist" class="item_list" cellspacing="0" cellpadding="0" border="0">
        <thead class="fields">
            <tr>
                <th class="first center nosort">&nbsp;&nbsp;Id&nbsp;&nbsp;</th>
                <th class="nosort"><input title="<?php echo ucfirst($txt->getWord('all')); ?>" class="select_all" type="checkbox" name="select_all" value="" /></th>
                <th class="nosort"><?php echo ucfirst($txt->getWord('name')); ?></th>
				<th class="nosort"><?php echo ucfirst($txt->getWord('label')); ?></th>
				<th class="nosort"><?php echo ucfirst($txt->getWord('info')); ?></th>
				<th class="nosort"><?php echo ucfirst($txt->getWord('class')); ?></th>
				<th class="nosort"><?php echo ucfirst($txt->getWord('type')); ?></th>
				<th class="nosort"><?php echo ucfirst($txt->getWord('validation')); ?></th>
				<th class="nosort"><?php echo ucfirst($txt->getWord('value')); ?></th>
				<th class="nosort"><?php echo ucfirst($txt->getWord('visible')); ?></th>
				<th class="nosort"><?php echo ucfirst($txt->getWord('required')); ?></th>
				<th class="nosort"><?php echo ucfirst($txt->getWord('min').'. '.$txt->getWord('chars')); ?></th>
				<th class="nosort"><?php echo ucfirst($txt->getWord('max').'. '.$txt->getWord('chars')); ?></th>
				<th class="nosort"><?php echo ucfirst($txt->getWord('no_space_char')); ?></th>
				<th class="nosort"><?php echo ucfirst($txt->getWord('compare_to')); ?></th>
				<th class="nosort"><?php echo ucfirst($txt->getWord('order')); ?></th>
                <th class="nosort"><?php echo ucfirst($txt->getWord('active')); ?></th>
                <th class="last nosort"><?php echo ucfirst($txt->getWord('delete')); ?></th>
            </tr>
        </thead>
        <tbody></tbody>
    </table>
</div>
<div id="add_dialog" title="<?php echo ucfirst($txt->getWord('new').' '.$txt->getWord('form_field')); ?>?" style="display:none; text-align:left;">
	<p>
		<?php echo ucfirst($txt->getWord('name')); ?>
		<input class="small" name="new_item_title" type="text" value="" maxlength="80" id="new_item_title" /><br />
	</p>
</div>
<div id="delete_dialog" title="<?php echo ucfirst($txt->getWord('delete').' '.$txt->getWord('form_field')); ?>?" style="display:none; text-align:left;">
	<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span><?php echo ucfirst($txt->getWord('sure_you_want_to_delete').' '.$txt->getWord('form_field')); ?></p>
</div>
<div id="src_dialog" title="<?php echo ucfirst($txt->getWord('source').' '.$txt->getWord('definition')); ?>?" style="display:none; text-align:left;">
	<p>
		<?php echo ucfirst($txt->getWord('source').' '.$txt->getWord('table')); ?><br />
		<input class="small-m" name="srcTable" type="text" value="" maxlength="100" id="srcTable" /><br />
		<?php echo ucfirst($txt->getWord('label').' '.$txt->getWord('field')); ?><br />
		<input class="small-m" name="srcLblSelect" type="text" value="" maxlength="100" id="srcLblSelect" /><br />
		<?php echo ucfirst($txt->getWord('values').' '.$txt->getWord('field')); ?><br />
		<input class="small-m" name="srcValSelect" type="text" value="" maxlength="100" id="srcValSelect" /><br />
		<?php echo ucfirst($txt->getWord('where').' '.$txt->getWord('statement')); ?><br />
		<input class="small-m" name="srcWhere" type="text" value="" maxlength="250" id="srcWhere" /><br />
		<?php echo ucfirst($txt->getWord('default').' '.$txt->getWord('value')); ?><br />
		<input class="small-m" name="srcValDef" type="text" value="" maxlength="100" id="srcValDef" /><br />
	</p>
</div>
<script type="text/javascript">

function srcOptions(id, table, label, val, where, def)
{
	jQuery('#srcTable').val(table);
	jQuery('#srcLblSelect').val(label);
	jQuery('#srcValSelect').val(val);
	jQuery('#srcWhere').val(where);
	jQuery('#srcValDef').val(def);
	
	jQuery('#src_dialog').dialog('open');
	jQuery('#src_dialog').dialog({
		bgiframe: true,
		resizable: false,
		height:300,
		modal: true,
		overlay: 
		{
			backgroundColor: '#000',
			opacity: 0.5
		},
		buttons: 
		{
			'<?php echo ucfirst($txt->getWord('cancel')); ?>': function() 
			{ jQuery(this).dialog('close'); },
			'<?php echo ucfirst($txt->getWord('save')); ?>': function() 
			{
				jQuery('#ff_srcTable_'+id).val(jQuery('#srcTable').val());
				jQuery('#ff_srcLblSelect_'+id).val(jQuery('#srcLblSelect').val());
				jQuery('#ff_srcValSelect_'+id).val(jQuery('#srcValSelect').val());
				jQuery('#ff_srcWhere_'+id).val(jQuery('#srcWhere').val());
				jQuery('#ff_srcValDef_'+id).val(jQuery('#srcValDef').val());
				jQuery(this).dialog('close');
				jQuery('#edit_form').submit();
			}
		}
	});
}

function addNewDialog(itemId)
{
	jQuery('#add_dialog').dialog('open');
	jQuery('#add_dialog').dialog({
		bgiframe: true,
		resizable: false,
		height:140,
		modal: true,
		overlay: 
		{
			backgroundColor: '#000',
			opacity: 0.5
		},
		buttons: 
		{
			'<?php echo ucfirst($txt->getWord('cancel')); ?>': function() 
			{
				jQuery(this).dialog('close');
			},
			'<?php echo ucfirst($txt->getWord('add')).' '.$txt->getWord('element'); ?>': function() 
			{
				jQuery.post("ajax.php?con=<?php echo $commander->getCon(); ?>&form=<?php echo $fc->getCurrentFormId(); ?>", 
				{ 
					action:'<?php echo $commander->getPostAction(); ?>', 
					new_item_title: jQuery('#new_item_title').val()} 
				).success(function() { loadItems(); });
				jQuery(this).dialog('close');
			}
		}
	});
}

function deleteDialog(itemId)
{
	jQuery('#delete_dialog').dialog('open');
	jQuery('#delete_dialog').dialog({
		bgiframe: true,
		resizable: false,
		height:140,
		modal: true,
		overlay: 
		{
			backgroundColor: '#000',
			opacity: 0.5
		},
		buttons: 
		{
			'<?php echo ucfirst($txt->getWord('no')); ?>': function() 
			{
				jQuery(this).dialog('close');
			},
			'<?php echo ucfirst($txt->getWord('delete')).' '.$txt->getWord('element'); ?>': function() 
			{
				jQuery.post("ajax.php?con=<?php echo $commander->getCon(); ?>&form=<?php echo $fc->getCurrentFormId(); ?>", 
				{ 
					action:'<?php echo $commander->getPostAction(); ?>', 
					del_item_id: itemId 
				}).success(function() { loadItems(); });
				jQuery(this).dialog('close');
			}
		}
	});
}

function loadItems()
{
	jQuery('table.item_list tbody').empty();
	jQuery('table.item_list tbody').html('<?php echo $commander->getComponentListLoading(); ?>'); 
	jQuery.ajax(
	{
		url: "ajax.php?con=<?php echo $commander->getCon(); ?>&form=<?php echo $fc->getCurrentFormId(); ?>",
		cache: false,
	  	success: function(html)
	  	{ 
			jQuery('table.item_list tr.loading').remove();
			jQuery("table.item_list tbody").append(html); 
			jQuery("#menulist").addClass('tablesorter');
		}
	});
}


jQuery(document).ready(function() 
{ loadItems(); });

</script>

